package reflect;

import java.io.File;
import java.io.FileFilter;
import java.net.URISyntaxException;

public class Test2 {
    public static void main(String[] args) throws URISyntaxException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        //定位当前类所在的字节码文件所在的目录
        File dir=new File(Test2.class.getResource(".").toURI());
        System.out.println(Test2.class.getResource(".").toURI());
       String packName= Test2.class.getPackage().getName();
        System.out.println("packName:"+packName);
      File[] subFiles= dir.listFiles( file ->file.getName().endsWith(".class"));
      for (File sub:subFiles){
          String fileName=sub.getName();
        String className=  sub.getName().substring(0,fileName.indexOf("."));
          System.out.println("className:"+className);
         Class cls= Class.forName(packName+"."+className);
        Object obj= cls.newInstance();
          System.out.println(obj);
      }



    }
}
